import * as constants from './constants'
import { getRedirectPath } from '../../util'

const defaultState = {
  user: '',
  pwd: '',
  type: '',
  msg: '',
  redirectTo: '',
  avatar: '',
  desc: '',
  title: '',
  company: '',
  money: '',
  list:[]
}
export default (state = defaultState, action) => {
  switch (action.type) {
    case constants.ERROR_MSG:
      return { ...state, msg: action.msg }
    case constants.SUCCESS_AUTH:
      return { ...state, ...action.payload, msg: '', redirectTo: getRedirectPath(action.payload) }
    case constants.LOAD_INFO:
      return { ...state, ...action.payload }
    case constants.CLEAR_REDUX:
      return { ...defaultState, redirectTo: '/login'}
    default:
      return state
  }
}